<template>
  <div class="app-container">
      <!-- <div class="right-detail"> -->
        <div class="cbox">
              <el-form class="form" ref="flt" :rules="rules" :inline="true" size="mini">
                      <el-form-item label="仲裁类型：" prop="arbitrationType">
                         <el-select  clearable v-model="from.arbitrationType">
                                <el-option
                                  v-for=" item in listDataA"
                                 :key="item.rvLowValue"
                                  :value="item.rvLowValue"
                                  :label="item.rvCmeaning"
                                ></el-option>
                              </el-select>
                      </el-form-item>
                    <el-form-item label="仲裁内容：" prop="arbitrationContent">
                      <el-input   placeholder="请输入仲裁内容" v-model="from.arbitrationContent" style="width:100%" clearable></el-input>
                    </el-form-item>
                  <el-form-item label-width="10px">
                        <el-button @click="searchType" type="primary">查询</el-button>
                      </el-form-item>
                </el-form>
            </div>
            <el-row :gutter="10" class="btn-area">
                <el-col :span="24">
                  <buttonName @clickEvent="clickEventDom"></buttonName>
                  <!-- <el-button size="mini" type="primary" plain v-if="isAuth('add')" @click="add">仲裁</el-button> -->
                  <!-- <el-button size="mini" type="danger" plain @click="examine">删除</el-button> -->
                  <!-- <el-button size="mini" type="primary" plain v-if="isAuth('del')" @click="del('diong')">审核</el-button> --> 
                </el-col>
            </el-row>
            <div class="table" ref="topType">
                <div class="inner" ref="inner">
                    <el-table
                        :data="DetailedData"
                        border
                        :height="maxHeight"
                        :header-cell-style="{ textAlign: 'center' }"
                        highlight-current-row
                        @row-dblclick='rowdbClickA'
                        @row-click="rowClick">
                        <el-table-column size="mini" align="center" :index="indexMethod" type="index" show-overflow-tooltip  label="序号" width="100"></el-table-column>
                        <!-- <el-table-column size="mini" prop="fltUuid" show-overflow-tooltip label="企业编号"></el-table-column> -->
                       <el-table-column size="mini" align="center" show-overflow-tooltip label="审核状态" prop="auditStatus">
                            <template slot-scope="scope">
                              <span>{{arbitrationStatusList[scope.row.auditStatus]}} </span>
                            </template>
                          </el-table-column>
                        <!-- <el-table-column size="mini" prop="arbitrationType" show-overflow-tooltip label="仲裁类型"></el-table-column> -->
                        <el-table-column size="mini" align="center" prop="arbitrationContent" show-overflow-tooltip label="仲裁内容"></el-table-column>
                        <el-table-column size="mini" align="center" prop="creator" show-overflow-tooltip label="仲裁操作人"></el-table-column>
                        <el-table-column size="mini" align="center" prop="created" show-overflow-tooltip label="仲裁时间"></el-table-column>
                        <el-table-column size="mini" align="center" prop="contactDetails" show-overflow-tooltip label="联系方式"></el-table-column>
                         <el-table-column size="mini" align="center" prop="editor" show-overflow-tooltip label="审核人"></el-table-column>
                          <el-table-column size="mini" align="center" prop="edited" show-overflow-tooltip label="审核时间"></el-table-column>
                          <el-table-column size="mini" align="center" prop="auditOpinon" show-overflow-tooltip label="审核意见"></el-table-column>
                    </el-table>
                </div>
          </div>
        <!-- 分页 -->
        <el-pagination
          class="pagination"
          small
          background
          ref="pagination"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="Pagination.currentPage"
          :page-sizes="Pagination.pageSizeList"
          :page-size="Pagination.pageSize"
          :layout="Pagination.layout"
          :total="Pagination.total"
        ></el-pagination>

        <!-- 弹出框 新增 编辑 -->
          <el-dialog
            v-el-drag-dialog
            width="40%"
            :title='addText'
            :visible.sync="addShowA"
            v-if="addShowA"
            :close-on-click-modal="false">
                <el-form  label-width="12rem" :model="xzData"  ref="xzData"  size="mini" :rules="addRules">
                    <el-row>
                        <el-col :span="20">
                          <el-form-item label="仲裁类型：" prop="arbitrationType">
                              <el-select  clearable v-model="xzData.arbitrationType" :disabled='disabled' >
                                <el-option
                                  v-for=" item in listDataA"
                                 :key="item.rvLowValue"
                                  :value="item.rvLowValue"
                                  :label="item.rvCmeaning"
                                ></el-option>
                              </el-select>
                          </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="20">
                          <el-form-item prop="arbitrationContent" label="仲裁内容：">
                            <el-input maxlength="100" :disabled='disabled' show-word-limit type="textarea" v-model="xzData.arbitrationContent" clearable></el-input>
                          </el-form-item>
                        </el-col>                        
                    </el-row>
                    <el-row>
                      <el-col :span="20">
                          <el-form-item prop="contactDetails" label="联系电话：">
                            <el-input maxlength="11" :disabled='disabled'  v-model="xzData.contactDetails" clearable></el-input>
                          </el-form-item>
                        </el-col>                       
                    </el-row>  
                     <el-row>
                      <el-col :span="20">
                        <el-form-item prop="created" label="仲裁时间：">
                         <div class="block">
                          <el-date-picker
                            v-model="xzData.created"
                            type="datetime"
                            placeholder="选择日期时间">
                          </el-date-picker>
                        </div>
                        </el-form-item>
                      </el-col>  
                    </el-row>   
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button size='mini'  @click="close">关闭</el-button>
                     <el-button size='mini' type="primary" v-if="see" @click="saveEditor('xzData')">保存</el-button>
                </div>
          </el-dialog>
           <el-dialog
            v-el-drag-dialog
            width="40%"
            :title='addText'
            :visible.sync="addShowB"
            v-if="addShowB"
            :close-on-click-modal="false">
                <el-form  label-width="12rem" :model="xzData"  ref="xzData"  size="mini" :rules="addRules">
                    <el-row>
                        <el-col :span="20">
                          <el-form-item label="仲裁类型：" prop="arbitrationType">
                              <el-select  clearable v-model="xzData.arbitrationType" :disabled='disabled' >
                                <el-option
                                  v-for=" item in listDataA"
                                 :key="item.rvLowValue"
                                  :value="item.rvLowValue"
                                  :label="item.rvCmeaning"
                                ></el-option>
                              </el-select>
                          </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                      <el-col :span="20">
                            <el-form-item prop="arbitrationContent" label="审核内容：">
                            <el-input maxlength="100" :disabled='disabled' show-word-limit type="textarea" v-model="xzData.arbitrationContent" clearable></el-input>
                          </el-form-item>
                        </el-col>
                        
                    </el-row>
                    <el-row>
                      <el-col :span="20">
                          <el-form-item prop="contactDetails" label="联系电话：">
                            <el-input maxlength="11" :disabled='disabled'  v-model="xzData.contactDetails" clearable></el-input>
                          </el-form-item>
                        </el-col>
                        
                    </el-row> 
                    <el-row>
                      <el-col :span="20">
                          <el-form-item prop="auditOpinon" label="审核意见：">
                              <el-input maxlength="100"  show-word-limit type="textarea" v-model="xzData.auditOpinon" clearable></el-input>
                          </el-form-item>
                        </el-col>
                    </el-row>  
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button size='mini'  @click="close">关闭</el-button>
                    <el-button size='mini' type="primary" v-if="see" @click="saveEditor('xzData')">保存</el-button>
                </div>
          </el-dialog>
  </div>
</template>

<script>
import {
  arbitrationListByCode,arbitrationTypeBidding,addArbitrationJ,auditAuctionArbitration
} from '@/request/api'
import resizeMixin from '@/mixins/resize'
import paginationMixin from '@/mixins/pagination' 
import isAuth from '@/mixins/buttonAuth'
import buttonName from '@/components/buttonName/button-name.vue'
export default {
  name: 'router.auctionArbitration',
  mixins: [resizeMixin,paginationMixin,isAuth],
  data(){
    return{
      from:{
        arbitrationContent:'',
        arbitrationType:''
      },
      item:{
        item:true,
        itemA:false
      },
      // options: [
      //   {
      //     value: 'Y',
      //     label: '激活'
      //   },
      //   {
      //     value: 'N',
      //     label: '未激活'
      //   }
      // ],
       arbitrationStatusList: {
          N: '已仲裁',
          Y: '已审核',
        },
      maxHeight:-1,
      disabled:false,
      disabledA:false,
      listData:[],
      listDataA:[],
      diong:'E',
      addText:'',
      addShowA:false, // 新增 
      addShowB:false, //  编辑
      see:true, //保存按钮
      DetailedData:[], //主列表的数据
      xzData:{},// 传给新增 编辑弹出框的数据
      PageIndexs:'',
      PageSizes:'',
      itemData:[], //当前行数据
      shiList:[], // 下拉框
      //表单验证 新增 编辑
      addRules:{
        
        arbitrationType:[
          { required: true, message: '请选择仲裁类型', trigger:'change'}
        ],
       
        arbitrationContent:[
          { required: true, message: '请填写仲裁内容', trigger:'blur'},
         
        ],
        
        contactDetails:[
          { required: true, message: '请填写联系人电话', trigger:'blur'}, 
          {
            pattern: /^[1-9]\d*$/,
            message: '请输入数字',
            trigger: 'blur'
          }
        ],
        auditOpinon:[
          { required: true, message: '请填写审核意见', trigger:'blur'},
           
        ],
        created:[
          { required: true, message: '请选择仲裁时间', trigger:'blur'},
           
        ],
      },
    }
  },
  created(){
    this.resize = () => {
      this.maxHeight = this.$refs.inner.offsetHeight
    }
  },
  mounted(){
    this.refreshList()
    this.arbitrationTypeBidding()
  },
  methods:{
    // 生成表格序号的方法
    indexMethod (index) {
      return 1 + index + (Number(this.Pagination.currentPage) - 1) * Number(this.Pagination.pageSize - 2)
    },
    // 切换大写
    uppercase(key) {
      this.xzData[key] = this.xzData[key].toUpperCase()
    },
    //仲裁类型下拉框
    arbitrationTypeBidding(){
      arbitrationTypeBidding().then(res=>{
        this.listDataA= res.data
        // console.log(this.listDataA)
      })
    },
    
    // 列表数据
    getList(currentPage, pageSize, updateTotal) {
      arbitrationListByCode({
        arbitrationContent:this.from.arbitrationContent,
        arbitrationType:this.from.arbitrationType,
        PageIndexs: this.Pagination.currentPage.toString(),
        PageSizes: this.Pagination.pageSize.toString()
      }).then(res => {
        this.DetailedData = res.data
        updateTotal(Number(res.total))
      })
    },
    // // 点击搜索
    searchType(){
      this.refreshList()
      this.close()
    },
    //新增
    add(){
      this.addText='仲裁'
      this.diong=''
      this.see = true
      this.addShowA=true
      this.disabled= false
      this.disabledA = false
      this.xzData = {
        // ctyeRemark:'',
        // ctyeCode:'',
        arbitrationType:'',
        arbitrationContent:'',
        contactDetails:'',
        arbitrationMode:'JJ',
        created:''
        // ctyeShrchn:'',
        // ctyeRemark:'',
        // ctyeIsvalid:'Y',
        // ctyePrename:''
      }
    },
    //编辑
    del(){
          if (this.itemData.auditStatus == 'Y') {
            this.$alert('该仲裁已审核，不可重复审核', '提示', {
              confirmButtonText: '确定'
            })
            return false
          }
      if(Object.keys(this.itemData).length){
        this.xzData = this.itemData
        this.addText='审核'
        this.diong='E'
        this.addShowB=true
        this.see = true
        this.disabled= true
        this.disabledA= true
      }else{
        this.$alert('请选择需要审核的内容', '提示', {
          confirmButtonText: '确定'
        })
        return false
      }
    },
    //删除
    examine(){
      if(Object.keys(this.itemData).length){
        this.$confirm('您确认要删除此内容吗?', '提示', {
          closeOnClickModal: false,
          
        }).then(() => {
          delcityManagement({ctyeCode:this.itemData.ctyeCode}).then(res=>{
            if(res.success !== '1'){
              this.$message ({
                type: 'success',
                message: '删除失败'
              })
              return
            }else{
              this.$message ({
                type: 'success',
                message: '删除成功'
              })
              this.refreshList()
              this.close()
            }
          })
        })
      }else{
        this.$alert('请选择需要删除的内容', '提示', {
          confirmButtonText: '确定'
        })
        return false
      }

    },
    //双击查看
    rowdbClickA(row){
      this.addText='查看'
      this.addShowA=true
      this.see=false
      this.xzData=row
      this.disabled= true
      this.disabledA= true
    },
    //新增 编辑  点击保存
    saveEditor(xzData){
      // console.log( this.$refs[xzData])
      this.$refs[xzData].validate((valid) => {
        if (valid) {
          if (this.diong ==='E') {
            auditAuctionArbitration(this.xzData).then(res=>{
              if(res.success !=='1'){
                this.$message ({
                  type: 'success',
                  message: '编辑失败'
                })
              }else{
                // this.xzData = []
                this.$message ({
                  type: 'success',
                  message: '编辑成功'
                })
                this.close()
                this.refreshList()
              }
            })
          }else{
            addArbitrationJ(this.xzData).then(res=>{
              if(res.success !== '1'){
                this.$message ({
                  type: 'success',
                  message: '添加失败'
                })
              }else{
                this.$message ({
                  type: 'success',
                  message: '添加成功'
                })
                this.close()
                this.refreshList()
                this.$refs[xzData].resetFields()
              }
            })

          }
        } else {
          return false
        }
      })
    },
    // 关闭弹出框
    close(){
      this.addShowA=false
       this.addShowB=false
       this.itemData = ''
    },
    //当前行数据
    rowClick(row){
      this.itemData = row
    },
  //调取父组件方法
    clickEventDom(item){
      if(item.mdlCode === 'add'){
        this.add()
      }else if(item.mdlCode === 'del'){
        this.del()
      }
    }
  },
  components: {
    buttonName
  },
}
</script>

<style  lang="scss" scoped>
.el-select {
  width: 100%;
}
.app-container {
  height: 100%;
  width: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
  .table {
    flex: 1;
    position: relative;
    overflow: hidden;
    .inner {
      width: 100%;
      height: 100%;
      overflow: hidden;
    }
    .el-pagination {
      height: 4rem;
      flex: 0 0 auto;
      margin: 1rem 0;
    }
  }
}
::v-deep .el-textarea__inner{
    height: 100px;
 }
</style>
